package com.sdust.pojos.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@Data
public class ArticleDoc {

    Integer id;

    Integer authorId;

    String authorName;

    String authorAvatar;

    String content;

    String title;

    String info;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    LocalDateTime updateTime;

    List<String> suggestion;

    public ArticleDoc(Article articleDoc) {
        this.id = articleDoc.getId();
        this.authorId = articleDoc.getAuthorId();
        this.authorName = articleDoc.getAuthorName();
        this.authorAvatar = articleDoc.getAuthorAvatar();
        this.content = articleDoc.getContent();
        this.title = articleDoc.getTitle();
        this.info = articleDoc.getInfo();
        this.updateTime = articleDoc.getUpdateTime();
        this.suggestion = Arrays.asList(this.title, this.authorName);
    }
}
